home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / rhythmbox / plugins / lyrics / LyricWikiParser.py < prev    next >
Encoding:
Python Source  |  2009-04-07  |  1.9 KB  |  55 lines

  1. # -*- Mode: python; coding: utf-8; tab-width: 8; indent-tabs-mode: t; -*-
  2. #
  3. # Copyright (C) 2007 Jonathan Matthew
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2, or (at your option)
  8. # any later version.
  9. #
  10. # The Rhythmbox authors hereby grant permission for non-GPL compatible
  11. # GStreamer plugins to be used and distributed together with GStreamer
  12. # and Rhythmbox. This permission is above and beyond the permissions granted
  13. # by the GPL license by which Rhythmbox is covered. If you modify this code
  14. # you may extend this exception to your version of the code, but you are not
  15. # obligated to do so. If you do not wish to do so, delete this exception
  16. # statement from your version.
  17. #
  18. # This program is distributed in the hope that it will be useful,
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. # GNU General Public License for more details.
  22. #
  23. # You should have received a copy of the GNU General Public License
  24. # along with this program; if not, write to the Free Software
  25. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA.
  26.  
  27.  
  28. import urllib
  29. import rb
  30. from xml.dom import minidom
  31.  
  32. class LyricWikiParser(object):
  33.     def __init__(self, artist, title):
  34.         self.artist = artist
  35.         self.title = title
  36.     
  37.     def search(self, callback, *data):
  38.         artist = urllib.quote(self.artist.replace(' ', '_'))
  39.         title = urllib.quote(self.title.replace(' ', '_'))
  40.  
  41.         htstring = 'http://lyricwiki.org/api.php?artist=%s&song=%s&fmt=text' % (artist, title)
  42.             
  43.         loader = rb.Loader()
  44.         loader.get_url (htstring, self.got_lyrics, callback, *data)
  45.  
  46.     def got_lyrics(self, result, callback, *data):
  47.         if result is None or result == "Not found":
  48.             callback (None, *data)
  49.             return
  50.  
  51.         result += "\n\nLyrics provided by lyricwiki.org"
  52.  
  53.         callback (result, *data)
  54.  
  55.